<%@ page import="cn.bai.mvc.Customer" %>
<%@ page import="java.util.List" %>
<%--
  Created by IntelliJ IDEA.
  User: Admin
  Date: 12/23 0023
  Time: 23:00
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<form action="query.do" method="post">
    <table>
        <tr>
            <td>Name:</td>
            <td><input type="text" name="name"/></td>
        </tr>
        <tr>
            <td>Address:</td>
            <td><input type="text" name="address"/></td>
        </tr>
        <tr>
            <td>Phone:</td>
            <td><input type="text" name="phone"/></td>
        </tr>
        <tr>
            <td><input type="submit" value="Query"/></td>
            <td><a href="/page/newcustomer.jsp">Add New Customer</a></td>
        </tr>
    </table>
</form>

<br><br><hr><br><br>
<%
    List<Customer> customers= (List<Customer>) request.getAttribute("customers");
    if(customers !=null && customers.size()>0){
%>

<br><br>
<table border="1" cellpadding="10" cellspacing="0">
    <tr>
        <th>ID</th>
        <th>Name</th>
        <th>Address</th>
        <th>Phone</th>
        <th>Update\Delete</th>
    </tr>
    <%
        for(Customer cus:customers){
    %>
    <tr>
        <td><%=cus.getId()%></td>
        <td><%=cus.getName()%></td>
        <td><%=cus.getAddress()%></td>
        <td><%=cus.getPhone()%></td>
        <td>
            <a href="edit.do?id=<%=cus.getId()%>">Update</a>
            <a href="delete.do?id=<%=cus.getId()%>" class="delete">Delete</a>
        </td>
    </tr>
    <%
        }
    %>
</table>
<%
    }
%>

<script type="text/javascript" src="/jquery-1.7.2.js"></script>
<script type="text/javascript">
    $(function () {
        $(".delete").click(function(){
            var contain=$(this).parent().parent().find("td:eq(1)").text();
            var flag=confirm("确定要删除"+contain+"信息吗?");
            return flag;
        })
    })
</script>
</body>
</html>
